package com.gitee.wsl.compose.ui.base

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DatePickerColors
import androidx.compose.material3.DatePickerDefaults
import androidx.compose.material3.DatePickerDialog
import androidx.compose.material3.DatePickerFormatter
import androidx.compose.material3.DateRangePicker
import androidx.compose.material3.DateRangePickerDefaults

import androidx.compose.material3.DateRangePickerState

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.material3.rememberDateRangePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties

object DatePicker {
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DatePicker.state() = rememberDatePickerState()

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DatePicker.Dialog(onDismissRequest: () -> Unit,
                      confirmButton: @Composable () -> Unit,
                      modifier: Modifier = Modifier,
                      dismissButton: @Composable (() -> Unit)? = null,
                      shape: Shape = DatePickerDefaults.shape,
                      tonalElevation: Dp = DatePickerDefaults.TonalElevation,
                      colors: DatePickerColors = DatePickerDefaults.colors(),
                      properties: DialogProperties = DialogProperties(usePlatformDefaultWidth = false),
                      content: @Composable ColumnScope.() -> Unit)
 = DatePickerDialog(onDismissRequest, confirmButton, modifier, dismissButton, shape, tonalElevation, colors, properties, content)

//fun DatePicker()=androidx.compose.material3.DatePicker()

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DatePicker.rangeState() = rememberDateRangePickerState()

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun DatePicker.Range(state: DateRangePickerState,
                     modifier: Modifier = Modifier,
                     dateFormatter: DatePickerFormatter = remember { DatePickerDefaults.dateFormatter() },
                     title: (@Composable () -> Unit)? = {
                         DateRangePickerDefaults.DateRangePickerTitle(
                             displayMode = state.displayMode,
                             modifier = Modifier.padding(DateRangePickerTitlePadding)
                         )
                     },
                     headline: (@Composable () -> Unit)? = {
                         DateRangePickerDefaults.DateRangePickerHeadline(
                             selectedStartDateMillis = state.selectedStartDateMillis,
                             selectedEndDateMillis = state.selectedEndDateMillis,
                             displayMode = state.displayMode,
                             dateFormatter,
                             modifier = Modifier.padding(DateRangePickerHeadlinePadding)
                         )
                     },
                     showModeToggle: Boolean = true,
                     colors: DatePickerColors = DatePickerDefaults.colors())
= DateRangePicker(state, modifier, dateFormatter, title, headline, showModeToggle, colors)


private val DateRangePickerTitlePadding = PaddingValues(start = 64.dp, end = 12.dp)
private val DateRangePickerHeadlinePadding =
    PaddingValues(start = 64.dp, end = 12.dp, bottom = 12.dp)